#include "Hcalc.h"


Hcalc::Hcalc(GameInfo& curr):
_curr(curr)
{
}


Hcalc::~Hcalc(void)
{
}

int Hcalc::HeuCalc(coord_t& coord, GameInfo& info)
{
	int	x = coord.x;
	int	y = coord.y;
	int	h = 0;

	int limitXRight = ((info.getPosXRight() + 1) < LENGTHBOARD ? info.getPosXRight() + 1 : info.getPosXRight());
	int limitYBot = ((info.getPosYBot() + 1) < LENGTHBOARD ? info.getPosYBot() + 1 : info.getPosYBot());

	for (y = (info.getPosYTop() > 0 ? info.getPosYTop() - 1 : 0);
		y <= limitYBot; y++)
	{
		for (x = (info.getPosXLeft() > 0 ? info.getPosXLeft() - 1 : 0);
			x <= limitXRight; x++)
		{
			if (CHECKMASK(info.getMap()[y][x], WHITE) == false) 
				h += LookingForNeigh(x, y, info);
			else
				h -= LookingForNeigh(x, y, info);
		}
	}
	return (h);
}

int Hcalc::LookingForNeigh(int x, int y, GameInfo& info)
{
	int h = 0;

	if (CHECKMASK(info.getMap()[x][y], TLH) && CHECKMASK(info.getMap()[x][y], TRH) )
		h += NBH(info.getMap()[x][y]) * NBH(info.getMap()[x][y]) * 350;
	else if (CHECKMASK(info.getMap()[x][y], TLH) || CHECKMASK(info.getMap()[x][y], TRH) )
		h += NBH(info.getMap()[x][y]) * NBH(info.getMap()[x][y]) * 250;
	else
		h += NBH(info.getMap()[x][y]) * NBH(info.getMap()[x][y]) *200;

	if (CHECKMASK(info.getMap()[x][y], TLV) && CHECKMASK(info.getMap()[x][y], TRV) )
		h += NBV(info.getMap()[x][y]) *NBV(info.getMap()[x][y])* 350;
	else if (CHECKMASK(info.getMap()[x][y], TLV) || CHECKMASK(info.getMap()[x][y], TRV) )
		h += NBV(info.getMap()[x][y]) *NBV(info.getMap()[x][y])* 250;
	else
		h += NBV(info.getMap()[x][y]) * NBV(info.getMap()[x][y])*200;

	if (CHECKMASK(info.getMap()[x][y], TLDSN) && CHECKMASK(info.getMap()[x][y], TRDSN) )
		h += NBDSN(info.getMap()[x][y]) * NBDSN(info.getMap()[x][y])*350;
	else if (CHECKMASK(info.getMap()[x][y], TLDSN) || CHECKMASK(info.getMap()[x][y], TRDSN) )
		h += NBDSN(info.getMap()[x][y]) * NBDSN(info.getMap()[x][y])*250;
	else
		h += NBDSN(info.getMap()[x][y]) * NBDSN(info.getMap()[x][y])*200;

	if (CHECKMASK(info.getMap()[x][y], TLDNS) && CHECKMASK(info.getMap()[x][y], TRDNS) )
		h += NBDNS(info.getMap()[x][y]) * NBDNS(info.getMap()[x][y]) *350;
	else if (CHECKMASK(info.getMap()[x][y], TLDNS) || CHECKMASK(info.getMap()[x][y], TRDNS) )
		h += NBDNS(info.getMap()[x][y]) * NBDNS(info.getMap()[x][y]) *250;
	else
		h += NBDNS(info.getMap()[x][y]) *NBDNS(info.getMap()[x][y]) *200;

	return h;
}
